package org.hackystat.devcathlon.ui.page.profile.manage;

import static org.junit.Assert.*;
import org.apache.wicket.util.tester.FormTester;
import org.apache.wicket.util.tester.WicketTester;
import org.hackystat.devcathlon.configuration.ConfigurationException;
//import org.hackystat.devcathlon.engine.profile.Profile;
import org.hackystat.devcathlon.engine.test.DevcathlonTestHelper;
import org.hackystat.devcathlon.ui.DevcathlonApplication;
//import org.hackystat.devcathlon.ui.DevcathlonSession;
import org.hackystat.devcathlon.ui.page.login.LoginPage;
import org.hackystat.devcathlon.ui.page.profile.ProfilePage;
import org.junit.Before;
import org.junit.Test;

/**
 * Test classes for the TeamsProfile. 
 *
 * @author Scheller Sanchez, Anthony Du
 *
 */
public class TestProfileManagePage extends DevcathlonTestHelper { 
  
  private String user = "admin@hackystat.org";
  private WicketTester tester;
  
  /**
   * Initialize profile manage page.
   * @throws ConfigurationException when an error occurs
   */
  @Before
  public void setUp() throws ConfigurationException {
    tester = new WicketTester(new DevcathlonApplication());
    tester.startPage(ProfilePage.class);
    tester.assertRenderedPage(LoginPage.class);    

    // Fill out the login form.
    FormTester formTester = tester.newFormTester("loginForm");
    formTester.setValue("user", user);
    formTester.setValue("password", user);
    formTester.submit();
    
    tester.assertRenderedPage(ProfilePage.class);
    tester.clickLink("ProfileManageLink");
    tester.assertRenderedPage(ProfileManagePage.class);
  }
  
  /**
   * Test profile update form.  
   */
  @Test
  public void testProfileUpdateForm() {
    // test wicket form exists
    assertNotNull("form should not be null", tester.getTagByWicketId("profileMgmtForm"));
//    // test submit form
//    Profile profile = DevcathlonSession.get().getProfileSession().getProfile();
//    // original contact
//    String contact = profile.getContact();
//    // new contact
//    String newContact = "808"; 
//    // form tester
//    FormTester form = tester.newFormTester("profileMgmtForm");
//    form.setValue("contact", newContact);
//    form.submit("updateButton"); // submit form via wicket:id of button
//    tester.assertRenderedPage(ProfilePage.class);
//    assertNotSame("should not be equal", profile.getContact(), contact);
  }
}